package com.zhengshang.common.pay.wxpay;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.zhengshang.common.constant.CommonConstants;
import com.zhengshang.common.constant.app.AppConstant;

/**
 * @author HY
 * @version 1.0.0
 * @ClassName WxPayUtils.java
 * @Description TODO
 * @createTime 2021年04月26日 16:30
 */
public class WxPayUtils {

    public final static String APP_ID = "wx3295ddbf467dd17a";
    public final static String MCH_KEY = "pFXUUX99lV0TKGb4tsIw3rlFOWl4nDEb";
    public final static String MCH_ID = "1607564186";
//    public final static String PRIVATE_CERT_PATH = Constant.class.getClassLoader().getResource("cert/apiclient_cert.p12").getPath();
    private static WxPayServiceImpl wxPayService;

    public static WxPayService getWxPayService(){
        if (wxPayService == null) {
            wxPayService = new WxPayServiceImpl();
            WxPayConfig payConfig = new WxPayConfig();
            payConfig.setAppId(WxPayUtils.APP_ID);
            payConfig.setNotifyUrl(CommonConstants.getWxNotifyUrl());
            payConfig.setSignType("MD5");
            payConfig.setMchKey(WxPayUtils.MCH_KEY);
            payConfig.setMchId(WxPayUtils.MCH_ID);
//            payConfig.setPrivateCertPath(WxPayUtils.PRIVATE_CERT_PATH);
            payConfig.setKeyPath(CommonConstants.getPrivateCertPath());
            wxPayService.setConfig(payConfig);
        }
        return wxPayService;
    }

}
